package controler;

import java.util.Observable;

import javax.swing.JList;
import javax.swing.event.ListSelectionListener;
import javax.swing.event.ListSelectionEvent;

import template.AbstractListener;

import utils.BookOfDelivery;

import model.BooleanModel;

import org.jdom.Element;

public class ChooseDeliveryListener extends AbstractListener implements ListSelectionListener{
	
	private static final long serialVersionUID = 1L;
	
	public ChooseDeliveryListener(Observable obs){
		addModel(obs);
	}
	
	@Override
	public void valueChanged(ListSelectionEvent evt){
		if(evt.getValueIsAdjusting() == false){
			BooleanModel model = (BooleanModel)getModel(0);
			
			JList list = (JList)evt.getSource();
			Element delivery = BookOfDelivery.getInstance().getDelivery(list.getSelectedIndex()+1);
			
			model.setValue((delivery.getChildText("gone").equals("yes")) ? false: true);
		}
	}
}
